<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title>邻和-微信模拟终端</title>
    <meta name="format-detection" content="telephone=no, address=no">
    <meta name="apple-mobile-web-app-capable" content="yes" /> <!-- apple devices fullscreen -->
    <meta name="apple-touch-fullscreen" content="yes"/>
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
    <meta name="keywords" content="微直达" />
    <meta name="description" content="微直达:直达天下，瞬息联通。" />

    <!-- Bootstrap -->
    <link href="business/resource/css/bootstrap.min.css" rel="stylesheet">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
    <script src="http://cdn.bootcss.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="http://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style>
        .row{
            padding-top: 5px;
        }
    </style>

    <?php


    ?>
</head>
<body>

<script src="business/resource/js/jquery-1.11.1.min.js"></script>
<script src="business/resource/js/bootstrap.min.js"></script>

<script type="text/javascript">
    <!--
    $(function(){
        console.log('JS页面初始化');
        $(":radio").click(function(){
            set_message($(this).val());
        });
        set_message('文本')
    });
    function send_message() {
        var tp=$("input[name='message_type']:checked").val();
        set_message(tp);
        //load_bar.setAttribute('class','active');
        var bar=$("#load_bar");
        bar.addClass('progress-bar-striped active');
        bar.width("10%");

        var pageUrl=$("#from_dianzhang").val();
        var xmlText=$("#message_text").val();
        // alert(xmlText);
        $.ajax( {
            url: pageUrl,// 跳转到 action
            data: xmlText,
            processData: false,
            contentType: 'text/xml',
            type:'post',
            cache:false,
            dataType:'text',
            success:function(data) {
                $("#load_bar").removeClass('active progress-bar-striped').width("100%");
                var history= $("#text_answer");
                var current=$('#response_div');
                if(data){
                    var dt=data;

                    history.val(dt+ history.val());

                    var ism= $.isXMLDoc(dt);
                    try {
                        var xm = $.parseXML(dt);
                        ism=true;
                    }catch(e){
                        ism=false;
                    }
                    if(ism) {
                        var msg=$(xm).find('Content');
                        if(msg) current.text(msg.text());
                        else current.text(dt);
                    }else
                        current.html(dt);
                }else{
                    current.text('响应超时');
                    history.val("响应超时\n"+history.val());
                    //alert(data);
                }
            },
            error : function() {
                $("#load_bar").removeClass('active progress-bar-striped');
                // view("异常！");
                alert("异常！");
            }
        });
    }


    function send_custommessage() {
        var tp=$("input[name='message_type']:checked").val();
//        set_message(tp);
        //load_bar.setAttribute('class','active');
        var bar=$("#load_bar");
        bar.addClass('progress-bar-striped active');
        bar.width("10%");

        var pageUrl=$("#interface").val();
        var xmlText=$("#message_text").val();
        // alert(xmlText);
        $.ajax( {
            url: pageUrl,// 跳转到 action
            data: xmlText,
            processData: false,
            contentType: 'text/xml',
            type:'post',
            cache:false,
            dataType:'text',
            success:function(data) {
                $("#load_bar").removeClass('active progress-bar-striped').width("100%");
                var history= $("#text_answer");
                var current=$('#response_div');
                if(data){
                    var dt=data;

                    history.val(dt+ history.val());

                    var ism= $.isXMLDoc(dt);
                    try {
                        var xm = $.parseXML(dt);
                        ism=true;
                    }catch(e){
                        ism=false;
                    }
                    if(ism) {
                        var msg=$(xm).find('Content');
                        if(msg) current.text(msg.text());
                        else current.text(dt);
                    }else
                        current.html(dt);
                }else{
                    current.text('响应超时');
                    history.val("响应超时\n"+history.val());
                    //alert(data);
                }
            },
            error : function() {
                $("#load_bar").removeClass('active progress-bar-striped');
                // view("异常！");
                alert("异常！");
            }
        });
    }

    function myisXML(elem){
        // documentElement is verified for cases where it doesn't yet exist
        // (such as loading iframes in IE - #4833)
        var documentElement = (elem ? elem.ownerDocument || elem : 0).documentElement;
        return documentElement ? documentElement.nodeName !== "HTML" : false;
    }
    function clear_board(){
        $("#text_answer").val('');
        $('#response_div').html('');
    }
    function trim_space_return(str){
        return str.replace(/(^\s*)|(\s*$)/g, "")
    }
    function set_message(tp){
        var msg=$("#content").val();
        var from=$("#from_user").val();
        var to=$("#to_user").val();
        var txt;
        switch(tp){
            case '文本':
                txt="<xml>"+
                "<ToUserName><![CDATA["+to+"]]></ToUserName>\n"+
                "<FromUserName><![CDATA["+from+"]]></FromUserName>\n"+
                "<CreateTime>1417954702</CreateTime>\n"+
                "<MsgType><![CDATA[text]]> </MsgType>\n"+
                "<Content><![CDATA["+msg+"]]> </Content>\n"+
                "<MsgId>1234567890123456</MsgId>"+
                "</xml>";
                break;
            case '菜单':
            //msg="MENU_RECOMMEND"
            txt="<xml>"+
            "<ToUserName><![CDATA["+to+"]]></ToUserName>\n"+
            "<FromUserName><![CDATA["+from+"]]></FromUserName>\n"+
            "<CreateTime>1417954702</CreateTime>\n"+
            "<MsgType><![CDATA[event]]> </MsgType>\n"+
            "<Event><![CDATA[CLICK]]> </Event>\n"+
            "<EventKey><![CDATA["+msg+"]]></EventKey>"+
            "</xml>";
                break;
            case '关注':
                txt="<xml>"+
                "<ToUserName><![CDATA["+to+"]]></ToUserName>\n"+
                "<FromUserName><![CDATA["+from+"]]></FromUserName>\n"+
                "<CreateTime>1417954702</CreateTime>\n"+
                "<MsgType><![CDATA[event]]></MsgType>\n"+
                "<Event><![CDATA[subscribe]]></Event> \n"+
                "<EventKey><![CDATA[]]></EventKey> </xml>";
                break;
            case '扫码':
                txt="<xml>"+
                "<ToUserName><![CDATA["+to+"]]></ToUserName>\n"+
                "<FromUserName><![CDATA["+from+"]]></FromUserName>\n"+
                "<CreateTime>1417954702</CreateTime>\n"+
                "<MsgType><![CDATA[event]]> </MsgType>\n"+
                "<Event><![CDATA[SCAN]]> </Event>\n"+
                "<EventKey><![CDATA["+msg+"]]></EventKey>"+
                "</xml>";
                break;
            case '注销':
                txt="<xml>"+
                "<ToUserName><![CDATA["+to+"]]></ToUserName>\n"+
                "<FromUserName><![CDATA["+from+"]]></FromUserName>\n"+
                "<CreateTime>1417954702</CreateTime>\n"+
                " <MsgType><![CDATA[event]]></MsgType> \n"+
                "<Event><![CDATA[unsubscribe]]></Event> \n"+
                "<EventKey><![CDATA[]]></EventKey> </xml>";
                break;
            case '帮助':
                txt="<xml>"+
                "<ToUserName><![CDATA["+to+"]]></ToUserName>\n"+
                "<FromUserName><![CDATA["+from+"]]></FromUserName>\n"+
                "<CreateTime>1417954702</CreateTime>\n"+
                " <MsgType><![CDATA[event]]></MsgType> \n"+
                "<Event><![CDATA[CLICK]]></Event> \n"+
                "<EventKey><![CDATA[MENU_HELP]]></EventKey> </xml>";
                break;
            case '出示二维码':
                txt="<xml>"+
                "<ToUserName><![CDATA["+to+"]]></ToUserName>\n"+
                "<FromUserName><![CDATA["+from+"]]></FromUserName>\n"+
                "<CreateTime>1417954702</CreateTime>\n"+
                " <MsgType><![CDATA[event]]></MsgType> \n"+
                "<Event><![CDATA[CLICK]]></Event> \n"+
                "<EventKey><![CDATA[MENU_USE_CARD]]></EventKey> </xml>";
                break;
            case '扫二维码':
                txt="<xml>"+
                "<ToUserName><![CDATA["+to+"]]></ToUserName>\n"+
                "<FromUserName><![CDATA["+from+"]]></FromUserName>\n"+
                "<CreateTime>1417954702</CreateTime>\n"+
                " <MsgType><![CDATA[event]]></MsgType> \n"+
                "<Event><![CDATA[scancode_waitmsg]]></Event> \n"+
                "<EventKey><![CDATA[MENU_SCAN1]]></EventKey>  \n"+
                "<ScanCodeInfo><ScanType><![CDATA[qrcode]]></ScanType> <ScanResult><![CDATA["+$("#from_bs").val()+"]]></ScanResult></ScanCodeInfo></xml>";

                break;

            default:
                txt='xmltext4';
        }
        $("#message_text").val(txt);
    }

    function openPage(page){
        var opid=$("#from_dianzhang").val();
        var publicnumber =$("#gzh_id").val();

        var str = '000{"publicnumber":"'+publicnumber+'" ,"0":"'+page+'"}';
         window.open("./business/index.php?state="+str+"&env=21901&openId="+opid);
    }
    function openTestPage(page){
        var y=confirm(page);
        if(y)
        window.open('test/'+page);
    }
    function closeWind(){
        WeixinJSBridge.invoke('closeWindow',{},function(res){
            //alert(res.err_msg);
            return true;
        });
    }


    -->
</script>

<div class="container-fluid">
    <div class="row">
     <div class="col-md-6">
         <div CLASS="panel panel-primary" >
             <div class="panel-body">

                         <div class="row">
                             <div class="input-group">
                                 <span class="input-group-addon"> 接 口 地 址: </span>
                                 <input type="text" class="form-control" id="interface" name="interface" value="wxinterface.php?test=true&appid=2" placeholder="接口地址">
                             </div>
                         </div>
                         <div class="row">
                             <div class="input-group">
                                 <span class="input-group-addon">用 户 编 号:</span>
                                 <input type="text" class="form-control" name="from_user" id="from_user" value="oPkLZsvsi4lSi6V-9LCsuJZMw9fo" placeholder="TesterOpenId">
                             </div>
                         </div>
                 <div class="row">
                     <div class="input-group">
                         <span class="input-group-addon">被扫二维码url:</span>
                         <input type="text" class="form-control" name="from_user" id="from_bs" value="http://weixin.qq.com/q/1EjTo8flLk1XghUmJmD8" placeholder="TesterOpenId">
                     </div>
                 </div>

                         <div class="row">
                             <div class="input-group">
                                 <span class="input-group-addon">公众号编号:</span>
                                 <input type="text" class="form-control" name="to_user" id="to_user" value="gh_d1de31ce1bc9" placeholder="公众号ID">
                             </div>
                         </div>
                         <div class="row" align="center" >
                             <label class="radio-inline">
                                 <input type="radio" name="message_type" id="inlineRadio1" checked value="文本"> 文本
                             </label>
                             <label class="radio-inline">
                                 <input type="radio" name="message_type" id="inlineRadio2" value="菜单"> 菜单
                             </label>
                             <label class="radio-inline">
                                 <input type="radio" name="message_type" id="inlineRadio3" value="关注"> 关注
                             </label>
                             <label class="radio-inline">
                                 <input type="radio" name="message_type" id="inlineRadio5" value="扫码"> 扫码
                             </label>
                             <label class="radio-inline">
                                 <input type="radio" name="message_type" id="inlineRadio4" value="注销"> 注销
                             </label>
                             <label class="radio-inline">
                                 <input type="radio" name="message_type" id="inlineRadio6" value="帮助"> 帮助
                             </label>
                            <!-- <label class="radio-inline">
                                 <input type="radio" name="message_type" id="inlineRadio7" value="出示二维码"> 出示二维码
                             </label>-->
                             <label class="radio-inline">
                                 <input type="radio" name="message_type" id="inlineRadio8" value="扫二维码"> 扫二维码
                             </label>


                         </div>
                         <div class="row">
                             <div class="input-group">
                                 <span class="input-group-addon">内 容 :</span>
                                 <input type="text" class="form-control" name="content" id="content" value="test message" placeholder="消息内容">
                             </div>
                         </div>
                         <div class="row" align="center">
                             <button type="button" class="btn btn-primary" onclick="send_message();">发送消息</button>
                             <button type="button" class="btn btn-primary" onclick="send_custommessage();">发送自定义消息</button>
                             <button type="button" class="btn btn-primary" onclick="clear_board();">清除回应内容</button>
                         </div>
                         <div class="row">
                             <textarea class="form-control" id="message_text" name="message_text" rows="8" title="message"></textarea>
                         </div>

                 <div class="row">
                     <div class="panel-body">

                         <div class="row">
                             <div class="input-group">
                                 <span class="input-group-addon">店 长 编 号:</span>
                                 <input type="text" class="form-control" name="from_dianzhang" id="from_dianzhang" value="oPkLZsvsi4lSi6V-9LCsuJZMw9fo" placeholder="TesterOpenId">
                             </div>
                         </div>
                         <div class="row">
                             <div class="input-group">
                                 <span class="input-group-addon">公众号:</span>
                                 <input type="text" class="form-control" name="gzh_id" id="gzh_id" value="2" placeholder="TesterOpenId">
                             </div>
                         </div>
                     </div>
                     <div class="panel panel-primary">
                         <div class="panel-body">
                             <button type="button" class="btn btn-default" onclick="openPage('myCards')">卡包</button>
                             <button type="button" class="btn btn-default" onclick="openPage('shopList')">铺列表</button>
                             <button type="button" class="btn btn-default" onclick="openPage('keyList')">字列表</button>
                             <button type="button" class="btn btn-default" onclick="openPage('UserInfo')">我</button>
                             <button type="button" class="btn btn-default" onclick="openPage('SellerHome')">卖家中心</button>
                             <button type="button" class="btn btn-default" onclick="openPage('Seller21QunLiao_List')">群聊</button>
                             <button type="button" class="btn btn-default" onclick="openPage('help')">帮助</button>
                         </div>
                     </div>
                 </div>
                 <div class="row">
                     <div class="panel panel-primary">
                         <div class="panel-body">
                            <button type="button" class="btn btn-default" onclick="openTestPage('addMenu.php')">定义菜单</button>
                         </div>
                     </div>
                 </div>
                 <div class="row">
                     <div class="panel panel-primary">
                         <div class="panel-body">
                             <button type="button" class="btn btn-default" onclick="openPage('MyProductList')"></button>
                         </div>
                     </div>
                 </div>
                     </div>
         </div>
     </div>

        <div class="col-md-6">
            <div class="panel panel-primary">
                <div class="panel-body">
                    <div class="row">
                        <div class="panel panel-info">

                            <div class="progress" style="background-color: lightblue">
                                <div class="progress-bar " id="load_bar" role="progressbar" aria-valuenow="100"  aria-valuemin="0" aria-valuemax="100" style="width: 1%">
                                    程序响应
                                </div>
                            </div>
                            <div class="panel-body" id="response_div" ></div>
                        </div>
                    </div>
                    <div class="row">
                        <textarea class="form-control" rows="20" name="text_answer" id="text_answer" placeholder="应答文本">empty</textarea>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

</body>
</html>